package com.lx.video.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lx.bilibili.entity.Videoplayhistroy;
import com.lx.video.biz.impl.VideoplayhistroyServiceImpl;
import com.lx.video.dao.VideoplayhistroyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lx
 * @since 2025-04-06
 */
@RestController
@RequestMapping("/videoplayhistroy")
public class VideoplayhistroyController {

    @Autowired
    VideoplayhistroyMapper videoplayhistroyMapper;

    @Autowired
    VideoplayhistroyServiceImpl videoplayhistroyService;

    @RequestMapping("getvideodenTime")
    public Videoplayhistroy getvideoHis(int uid, int vid){
        LambdaQueryWrapper<Videoplayhistroy> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Videoplayhistroy::getUid, uid);
        lqw.eq(Videoplayhistroy::getVid, vid);
        lqw.select(Videoplayhistroy::getEndtime);
        return videoplayhistroyMapper.selectOne(lqw);
    }

    @RequestMapping("saveVideoProgress")
    public int saveVideoProgress(@RequestBody Videoplayhistroy videoplayhistroy){
        if(videoplayhistroy.getUid() == null){
            return 0;
        }
        videoplayhistroy.setTime(LocalDateTime.now());
        return videoplayhistroyService.saveVideoProgress(videoplayhistroy);
    }
}
